package com.raymond.sgip.codec.encodeing;

import com.raymond.client.msg.BaseMessage;
import com.raymond.client.utils.NettyByteBufUtil;
import com.raymond.cmpp.utils.CommonUtil;
import com.raymond.sgip.constants.SgipConstants;
import com.raymond.sgip.msg.response.ReportResponseMessage;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

/**
 * 状态报告和上行响应编码
 *
 * @author :  raymond
 * @version :  V1.0
 * @date :  2021-08-09 15:15
 */
public class ReportResponseMessageEncoder extends BaseSgipEncoder {
    @Override
    public byte[] encode0(BaseMessage msg) throws Exception {
        ReportResponseMessage responseMessage = (ReportResponseMessage) msg;
        ByteBuf bodyBuffer = Unpooled.buffer();
        bodyBuffer.writeByte(responseMessage.getResult());
        bodyBuffer.writeBytes(CommonUtil.ensureLength(responseMessage.getReserve().getBytes(SgipConstants.DEFAULT_TRANSPORT_CHARSET),
                8));
        return NettyByteBufUtil.toArray(bodyBuffer);
    }
}
